package net.loststone.dao

import org.springframework.beans.factory.InitializingBean
import com.mongodb.Mongo
import com.mongodb.DBCollection
import com.mongodb.DBObject

class JobService implements InitializingBean {

    private static final String NOM_DB = "patopay"
    private static final String NOM_COLLECIO = "jobs"

    Mongo mongoDb;
    DBCollection jobsCollection;

    static transactional = true

    // inicialitzacio
    void afterPropertiesSet() {
        mongoDb = new Mongo();
        def db = mongoDb.getDB(NOM_DB)
        jobsCollection = db.getCollection(NOM_COLLECIO)
    }


    def guardarJob(DBObject job) {
        jobsCollection.save(job)
    }

    def agafarJob() {
        println jobsCollection.findOne()
    }
}
